import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6])
newarr = np.array_split(arr, 3) #并不是对np array进行split，返回的时候发生了copy操作
print(" np.array_split(arr, 3):", newarr,"type:", type(newarr),"len:", len(newarr))

#If the array has less elements than required, it will adjust from the end accordingly.
arr = np.array([1, 2, 3, 4, 5, 6])
newarr = np.array_split(arr, 4)
#[1,2],[3,4],[5],[6] 这个split的结果真奇怪
print(" np.array_split(arr, 4):", newarr,"type:", type(newarr),"len:", len(newarr))

#Split into Arrays
arr = np.array([1, 2, 3, 4, 5, 6])
newarr = np.array_split(arr, 3)
print(newarr[0],newarr[1],newarr[2])
#Splitting 2-D Arrays
arr = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]])
newarr = np.array_split(arr, 3)#按照point 来分组，注意这里的axis是分组的标志，只有0，1两种类型
print(" np.array_split(arr, 3):", newarr,"type:", type(newarr),"len:", len(newarr))

#将一个2DArray 分割成3个2DArray
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]])
newarr = np.array_split(arr, 3, axis=1)# 与按照x，y，z来分组一直，将交错数组按照属性列来分组。
print(" np.array_split(arr, 3, axis=1):", newarr,"type:", type(newarr),"len:", len(newarr))

#hsplit 拆分，它没有axis参数
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]])
newarr = np.hsplit(arr, 3)#等价于 np.array_split(arr, 3, axis=1)
print(" np.hsplit(arr, 3):", newarr,"type:", type(newarr),"len:", len(newarr))